package cn.org.eshow.webapp.action.h5;

import cn.org.eshow.bean.query.ProductCommentQuery;
import cn.org.eshow.common.page.Page;
import cn.org.eshow.model.ProductComment;
import cn.org.eshow.service.ProductCommentManager;
import cn.org.eshow.util.PageUtil;
import cn.org.eshow.webapp.action.BaseAction;
import org.apache.struts2.convention.annotation.AllowedMethods;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Results({@Result(name = "input", location = "/add"),
        @Result(name = "list", type = "redirect", location = "/productComment/"),
        @Result(name = "success", type = "redirect", location = "/view/${id}"),
        @Result(name = "redirect", type = "redirect", location = "${redirect}")})
@AllowedMethods({"search", "list", "view", "check"})
public class ProductCommentAction extends BaseAction {

    private static final long serialVersionUID = 1L;

    @Autowired
    private ProductCommentManager productCommentManager;

    private List<ProductComment> productComments;
    private ProductComment productComment = new ProductComment();
    private ProductCommentQuery query = new ProductCommentQuery(true);


    public void search() {
        Page<ProductComment> page = productCommentManager.search(query);
        productComments = page.getDataList();
        saveRequest("page", PageUtil.conversion(page));
        saveRequest("query", query);
    }


    public String view() {
        if (id != null) {
            productComment = productCommentManager.get(id);
        } else {
            return INDEX;
        }
        return NONE;
    }

    public String check() {
        productComment = productCommentManager.check(query);
        return LIST;
    }

    public List<ProductComment> getProductComments() {
        return productComments;
    }

    public void setProductComments(List<ProductComment> productComments) {
        this.productComments = productComments;
    }

    public ProductComment getProductComment() {
        return productComment;
    }

    public void setProductComment(ProductComment productComment) {
        this.productComment = productComment;
    }

    public ProductCommentQuery getQuery() {
        return query;
    }

    public void setQuery(ProductCommentQuery query) {
        this.query = query;
    }
}